package com.gang.ssm.bos.system.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gang.ssm.bos.common.Page;
import com.gang.ssm.bos.core.anotation.Permission;
import com.gang.ssm.bos.core.toolbox.ajax.AjaxResult;
import com.gang.ssm.bos.system.bean.Subarea;
import com.gang.ssm.bos.system.service.RegionService;
import com.gang.ssm.bos.system.service.SubareaService;

/**
 * 分区
 * @author Administrator
 */
@RequestMapping("/subarea")
@Controller
public class SubareaController extends BosController {
	
	@Autowired
	private SubareaService subareaService;
	
	@Autowired
	private RegionService regionService;
	
	@RequestMapping("/list")
	public String list(Page<Subarea> page, Map<String, Object> map) {
		subareaService.pageQuery(page);
		map.put("page", page);
		return "system/base/subareaList";
	}
	
	@RequestMapping("/subarea")
	public String input(Integer id, Map<String, Object> map) {
		if(id != null) {
			map.put("subarea", subareaService.findById(id));
		}
		
		return "system/base/subarea";
	}
	
	@Permission({ADMIN})
	@ResponseBody
	@RequestMapping("/save")
	public AjaxResult save(Subarea subarea) {
		try {
			subareaService.saveOrUpdate(subarea);
			return success("保存成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail("保存失败!");
	}
	
	@Permission({ADMIN})
	@ResponseBody
	@RequestMapping("/delete")
	public AjaxResult delete(Integer id) {
		try {
			subareaService.deleteById(id);
			return success();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fail();
	}
}
